package org.leetcode.middle.leetcode150;

import java.util.Arrays;
import java.util.LinkedList;

public class Solution
{

    public int evalRPN2(String[] tokens)
    {
        //需要注意-和/两种情况下数字的位置

        LinkedList<Integer> stack = new LinkedList<>();

        for (String s :tokens)
        {
            if ("+".equals(s))
            {
                stack.push(stack.pop()+stack.pop());
            }else if ("-".equals(s))
            {
                stack.push(-stack.pop()+stack.pop());
            }else if ("*".equals(s))
            {
                stack.push(stack.pop()* stack.pop());
            }else if ("/".equals(s))
            {
                int temp1 =stack.pop();
                int temp2 =stack.pop();
                stack.push(temp2/temp1);
            }else {
                stack.push(Integer.valueOf(s));
            }
        }

        return stack.pop();

    }
    /**
     * 未完成
     * @param tokens
     * @return
     */
    public int evalRPN(String[] tokens)
    {
        LinkedList<String> stack = new LinkedList<String>();


        for (int i = tokens.length-1; i >=0 ; i--) {
            stack.push(tokens[i]);
        }

//        for (int i = 0; i < tokens.length; i++) {
//            stack.push(tokens[i]);
//        }

        int num1=0,num2,res=0;
        while (!stack.isEmpty())
        {
            String poll = stack.poll();

            if (poll=="+")
            {
                res=num1+res;
            }else if (poll=="-")
            {

            }else if (poll=="*")
            {

            }else if (poll=="/")
            {

            }else {
                //为数字
                num1= Integer.parseInt(poll);
            }
        }

        return 2;
    }

    public static void main(String[] args) {

    }
}
